package dao

import "time"

type UserEntity struct {
	Id        int64
	Username  string
	Password  string
	Email     string
	CreatedAt time.Time
}

// TableName 表名
func (UserEntity) TableName() string {
	return "user"
}

// UserDAO UserDao 接口
type UserDAO interface {
	SelectByEmail(email string) (*UserEntity, error)
	Save(user *UserEntity) error
}

// UserDAOImpl UserDao 实现
type UserDAOImpl struct {
}

// SelectByEmail 通过 email 查询 UserEntity
func (userDAO *UserDAOImpl) SelectByEmail(email string) (*UserEntity, error) {
	user := &UserEntity{}
	err := db.Where("email = ?", email).First(user).Error
	return user, err
}

// Save 保存 UserEntity
func (userDAO *UserDAOImpl) Save(user *UserEntity) error {
	return db.Create(user).Error
}
